﻿<Window x:Class="Demo.DataFormWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:my="clr-namespace:Demo" mc:Ignorable="d" 
        xmlns:res="clr-namespace:Demo.Properties"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:uia="clr-namespace:Thinktecture.DataForm;assembly=Thinktecture.DataForm"
        xmlns:dataform="clr-namespace:Thinktecture.DataForm;assembly=Thinktecture.DataForm"
        xmlns:controls="clr-namespace:Thinktecture.DataForm.Controls;assembly=Thinktecture.DataForm"
        FontFamily="Calibri"  FontSize="14" TextOptions.TextRenderingMode="ClearType" TextOptions.TextFormattingMode="Display" UseLayoutRounding="True"
        Title="DataForm Demo" Loaded="Window_Loaded" WindowStartupLocation="CenterScreen"
        SizeToContent="Manual" Height="520" Width="470" MinWidth="350">
    
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>

        <dataform:DataForm x:Name="personDataForm" 
            HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="12,12,12,0" 
            BorderBrush="Black" BorderThickness="1" AutoGenerateColumns="true"
            ColumnSpacing="5" RowSpacing="5" CornerRadius="0" Padding="10,10,10,10" 
            ShowHeader="True" ShowFooter="True" ShowEditTracker="True" ShowRowMarker="True" ShowRequiredFieldMarker="True" ShowErrorMarker="True"
            AllowAddNew="true" AllowRemove="true" IsReadOnly="false" IsEnabled="True" ShowDropShadow="True"
            ValidationError="OnValidationError" ItemAdded="OnItemAdded" ItemRemoved="OnItemRemoved" ItemChanged="OnItemChanged"
            AddCommand="{Binding AddCommand}" RemoveCommand="{Binding RemoveCommand}" ActionCommand="{Binding ActionCommand}"
            Title="PersonTitleText" DefaultStatusText="PersonDefaultStatusText" ResourceType="{x:Type res:Resources}"
            SelectionButtonsText="PersonSelectImageText" DefaultImage="/Demo;component/Images/UserAnonymous.png"
            SelectionButtonCommand="{Binding SelectionButtonCommand}" HasError="{Binding Path=HasError, Mode=OneWayToSource}"
            BusyIndicatorType="Wheel"  DataSource="{Binding Persons}" ColumnCount="1">

            <!--Set sub data sources-->
            <dataform:DataForm.SubDataSources>
                <dataform:DataFormSubSource EntityPropertyName="Department" DataSourcePropertyName="Departments" />
            </dataform:DataForm.SubDataSources>

            <!--Customizing the field mappings-->
            <!--<dataform:DataForm.ControlMappings>
                <dataform:ControlMapping ControlType="{x:Type TextBox}" BindingPropertyName="Text" DataPropertyName="Id" />
                <dataform:ControlMapping DataType="{x:Type sys:String}" ControlType="{x:Type TextBox}" BindingPropertyName="Text" />
                <dataform:ControlMapping DataType="{x:Type sys:DateTime}" IsReadOnly="True" IsRequired="False" Description="Birthday of the person.">
                    <dataform:ControlMapping.ColumnTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=Birthday, StringFormat={}{0:dd. MMMM yyyy}}" IsReadOnly="False" />
                        </DataTemplate>
                    </dataform:ControlMapping.ColumnTemplate>
                </dataform:ControlMapping>
            </dataform:DataForm.ControlMappings>-->

            <!--Customizing the items-->
            <!--<dataform:DataForm.DataFormItems>
                <dataform:DataFormItem Header="Id:">
                    <dataform:DataFormItem.Content>
                        <controls:NumericUpDown Width="100" HorizontalAlignment="Left"
                            Value="{Binding Path=Id, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
                    </dataform:DataFormItem.Content>
                </dataform:DataFormItem>
                <dataform:DataFormItem>
                    <dataform:DataFormItem.Header>
                        <TextBlock Text="Name:" />
                    </dataform:DataFormItem.Header>
                    <dataform:DataFormItem.Content>
                        <TextBox Text="{Binding Path=Name, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                            uia:Annotations.CueBanner="Enter the full name!" />
                    </dataform:DataFormItem.Content>
                </dataform:DataFormItem>
                <dataform:DataFormItem Header="Birthday:">
                    <dataform:DataFormItem.Content>
                        <DatePicker SelectedDate="{Binding Birthday}"
                                    uia:Annotations.CueBanner="Choose a date!" />
                    </dataform:DataFormItem.Content>
                </dataform:DataFormItem>
                <dataform:DataFormItem Header="Department:">
                    <dataform:DataFormItem.Content>
                        <ComboBox SelectedItem="{Binding Path=Department, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                  DisplayMemberPath="Name" />
                    </dataform:DataFormItem.Content>
                </dataform:DataFormItem>
            </dataform:DataForm.DataFormItems>-->

            <!--Customizing the header style-->
            <!--<dataform:DataForm.HeaderStyle>
                <Style TargetType="{x:Type dataform:DataFormHeader}">
                    <Setter Property="Background" Value="LightYellow" />
                    <Setter Property="MoveFirstImage" Value="/Demo;component/Images/Navigation_First.png" />
                    <Setter Property="MovePreviousImage" Value="/Demo;component/Images/Navigation_Previous.png" />
                    <Setter Property="MoveNextImage" Value="/Demo;component/Images/Navigation_Next.png" />
                    <Setter Property="MoveLastImage" Value="/Demo;component/Images/Navigation_Last.png" />
                    <Setter Property="AddImage" Value="/Demo;component/Images/New.png" />
                    <Setter Property="RemoveImage" Value="/Demo;component/Images/Delete.png" />
                </Style>
            </dataform:DataForm.HeaderStyle>-->
            
            <!--Customizing the header template-->
            <!--<dataform:DataForm.HeaderTemplate>
                <ControlTemplate>
                    <Border BorderThickness="0,0,0,1" BorderBrush="Black" Background="WhiteSmoke">
                        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                            <Button Content="|&lt;" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=MoveFirstCommand}" />
                            <Button Content="&lt;" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=MovePreviousCommand}" />
                            <Button Content="&gt;" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=MoveNextCommand}" />
                            <Button Content="&gt;|" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=MoveLastCommand}" />
                            <Line X1="0.5" X2="0.5" Y1="4" Y2="23" Stroke="Gray" StrokeThickness="1" Margin="2,0,2,0" />
                            <Button Content="+" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=AddCommand}" IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AllowAddNew}"/>
                            <Button Content="-" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=RemoveCommand}" IsEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=AllowRemove}"/>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </dataform:DataForm.HeaderTemplate> -->

            <!--Customizing the footer-->
            <!--<dataform:DataForm.FooterStyle>
                <Style TargetType="{x:Type dataform:DataFormFooter}">
                    <Setter Property="Background" Value="LightYellow" />
                    <Setter Property="ErrorBackground">
                        <Setter.Value>
                            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                <GradientStop Color="#FFFCABAB" Offset="0" />
                                <GradientStop Color="#FFFC1313" Offset="1" />
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="ErrorForeground" Value="Black" />
                    <Setter Property="ErrorImage" Value="/Demo;component/Images/Error.png" />
                    <Setter Property="DescriptionImage" Value="/Demo;component/Images/info.png" />
                </Style>
            </dataform:DataForm.FooterStyle>-->

            <!--Customizing the footer template-->
            <!--<dataform:DataForm.FooterTemplate>
                <ControlTemplate>
                    <Border Background="Black" TextElement.Foreground="White"
                            BorderBrush="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=BorderBrush}"
                            BorderThickness="0,1,0,0" Padding="4"
                            CornerRadius="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=CornerRadius}"
                            Opacity="0.8" >
                        <Grid>
                            <Grid.Resources>
                                <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
                                <dataform:ReverseBooleanToVisibilityConverter x:Key="ReverseBooleanToVisibilityConverter" />
                            </Grid.Resources>
                            <StackPanel x:Name="PART_InfoBar" Orientation="Horizontal" MinHeight="20"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=HasError, Converter={StaticResource ReverseBooleanToVisibilityConverter}}">
                                <Image Source="/Thinktecture.DataForm;component/Images/Infos.png" Stretch="None" VerticalAlignment="Center"/>
                                <TextBlock x:Name="PART_StatusTextBlock" Margin="5,0,0,0" TextWrapping="NoWrap" VerticalAlignment="Center"
                            Text="Ready." />
                            </StackPanel>
                            <StackPanel x:Name="PART_ErrorBar" Opacity="1" Orientation="Horizontal" MinHeight="20"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=HasError, Converter={StaticResource BooleanToVisibilityConverter}}">
                                <Image Source="/Thinktecture.DataForm;component/Images/Error.png" Stretch="None" VerticalAlignment="Center" />
                                <TextBlock Margin="5,0,0,0" TextWrapping="Wrap" VerticalAlignment="Center"
                            Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type dataform:DataForm}}, Path=Error}" />
                            </StackPanel>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </dataform:DataForm.FooterTemplate>-->

            <!--Customizing the field marker-->
            <!--<dataform:DataForm.MarkerStyle>
                <Style TargetType="{x:Type dataform:Marker}">
                    <Setter Property="EditTrackerImage" Value="/Demo;component/Images/Edit.png" />
                    <Setter Property="FieldTrackerImage" Value="/Demo;component/Images/ArrowFore.png" />
                    <Setter Property="ErrorImage" Value="/Demo;component/Images/error.png" />
                    <Setter Property="RequiredFieldImage" Value="/Demo;component/Images/Required.png" />
                </Style>
            </dataform:DataForm.MarkerStyle>-->

            <!--Customizing the busy indicator-->
            <!--BusyIndicatorTemplate="{StaticResource CustomBusyIndicatorTemplate}"-->
            <!--set also BusyIndicatorType="Wheel" on the DataForm-->

            <!--Set DataForm background-->
            <dataform:DataForm.Background>
                <RadialGradientBrush>
                    <GradientStop Color="#FFFCFCFC" Offset="0" />
                    <GradientStop Color="#FFEFEFFC" Offset="0.373" />
                    <GradientStop Color="#FFDCDCF8" Offset="1" />
                </RadialGradientBrush>
            </dataform:DataForm.Background>
            
        </dataform:DataForm>
        
        <Button Content="Save" Command="{Binding SaveCommand}" Height="23" HorizontalAlignment="Right" Margin="0,12,93,12" IsDefault="True" VerticalAlignment="Bottom" Width="75" Grid.Row="1" Grid.Column="1"/>
        <Button Content="Cancel" Height="23" HorizontalAlignment="Right" Margin="12,12,12,12" Name="cancelButton" IsCancel="true" VerticalAlignment="Bottom" Width="75" Grid.Row="1" Grid.Column="1" Click="cancelButton_Click" />
        
        <TextBlock Name="eventTextBlock" Grid.Row="1" Height="23" HorizontalAlignment="Left" Margin="12,15,0,0" VerticalAlignment="Top" Width="188"
                   Visibility="Collapsed"/>
    </Grid>
</Window>
